#ifndef __FILESYS__
#define __FILESYS__

#include "../lib/def.h"
#include "../lib/rtl.h"
#include "../dev/disk.h"

#define SUPER_BLOCK_LOCATION 1
#define SUPER_BLOCK_MAGIC 0x53595346

#define FILE_INODE_MAGIC 0x454C4946

#define FILE_TYPE_UNKNOWN 0
#define FILE_TYPE_FOLDER 1
#define FILE_TYPE_DEFAULT 2

#define FILE_ATTR_KERNEL 0x00000001
#define FILE_ATTR_COMPRESSED 0x00000002
#define FILE_ATTR_ENCRYPTED 0x00000004
#define FILE_ATTR_HIDDEN 0x00000008
#define FILE_ATTR_SYSTEM 0x00000010

typedef struct {
    DWORD dwMagic;
    DWORD dwSectors;
    DWORD dwRoot; 
    DWORD dwReserved[0x7D];
} SUPER_BLOCK, * PSUPER_BLOCK, *FAR LPSUPER_BLOCK;

typedef struct {
    CHAR lpcName[0x40];
    DWORD dwLength;
    DWORD dwAttribute;
    DWORD dwType;
    DWORD dwSuper;
    DWORD dwMagic;
    DWORD dwAddress[0x6A];
    DWORD dwNext;
} INODE, *PINODE, *FAR LPINODE;

VOID FsSuperBlockInitialize(VOID);

VOID FsInitialize(VOID);
DWORD FsGetRootNode(VOID);
DWORD FsAllocateSector(VOID);
VOID FsAllocateSectors(BOOLEAN (*lpfnCallback)(DWORD_PTR));
VOID FsFreeSector(DWORD dwAddress);
DWORD FsCreateFile(DWORD dwBase, LPCSTR lpszFilename);
DWORD FsOpenFile(DWORD dwBase, LPCSTR lpszFilename);
VOID FsDeleteFile(DWORD dwBase, LPCSTR lpszFilename);
VOID FsGetFileName(DWORD dwFile, LPSTR lpszBuffer);
BOOL FsGetFileAttributes(DWORD dwFile, LPDWORD lpdwLength, LPDWORD lpdwAttributes, LPDWORD lpdwSuper, LPDWORD lpdwType);
VOID FsReadFile(DWORD dwFile, DWORD dwStart, LPVOID lpvBuffer, DWORD dwLength, LPDWORD dwBytesOfRead);
VOID FsWriteFile(DWORD dwFile, DWORD dwStart, LPCVOID lpvBuffer, DWORD dwLength, LPDWORD dwBytesOfWrite);
DWORD FsCreateDirectory(DWORD dwBase, LPCSTR lpszDirname);
DWORD FsOpenDirectory(DWORD dwBase, LPCSTR lpszDirname);
VOID FsDeleteDirectory(DWORD dwBase, LPCSTR lpszDirname);
VOID FsFindAllFiles(DWORD dwBase, VOID (*lpfnCallback)(DWORD));

#endif
